package file;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import data.Data;

public class Parser {

	List<Data> list;
	double avg;

	public Parser(String dir) throws IOException {
		String line;
		double sumTest = 0.0;
		BufferedReader br = new BufferedReader(new FileReader(dir));
		List<Data> test = new ArrayList<Data>();

		while((line = br.readLine()) != null){

			String[] fields = line.split(",");
			int uid = Integer.parseInt(fields[0]);
			short iid = Short.parseShort(fields[1]);
			byte rat = Byte.parseByte(fields[2]);	
			
			test.add(new Data(uid,iid,rat));	
			
			sumTest += rat;
		}
		br.close();
		
//		System.out.println("Number of ratings in test: "+test.size());
		
		double avgTest = sumTest / test.size();
//		System.out.println("Avg. of ratings in test: "+avgTest);
		
		this.list = test;
		this.avg = avgTest;
	}
	
	public List<Data> getList() {
		return list;
	}
	public double getAvg() {
		return avg;
	}
}
